package blyth;

import jason.asSemantics.*;
import jason.asSyntax.*;

/*
 * This class is responsible for the "katz.Action(A,B,C)"
 * function in Jason.
 */
public class Action extends DefaultInternalAction {

    private static final long serialVersionUID = 4L;
    
    /*
    // Used at the debug win
    public static String TeamName = "Blyth v6";
    
    // Refresh the debug win only at every 500 turn
    public static boolean refreshRarely = false;
    public static int lastRefresh = -500;
    
    // My debug window
    public static DebugWin debugWin = new DebugWin(TeamName);    
    
    public static void RefreshDebugWin() {
        if (refreshRarely) {
            if (World.turn - lastRefresh >= 500) {
                lastRefresh = World.turn;
                Action.debugWin.SetText(knowledge.toString());
            }
        } else {
            Action.debugWin.SetText(knowledge.toString());
        }
    }
    */
    
    // My Knowledge
    public static Knowledge knowledge = new Knowledge();
    
    @Override
    public Object execute(TransitionSystem ts, final Unifier un, final Term[] arg) throws Exception {

        Command command =
                knowledge.Act(
                new Beliefs(ts.getAg().getBB().toString()));
        
        //RefreshDebugWin();

        NumberTermImpl actionType = new NumberTermImpl(command.actionType.ordinal()),
                p1 = new NumberTermImpl(command.param1),
                p2 = new NumberTermImpl(command.param2);

        return (un.unifies(actionType, arg[0]) && un.unifies(p1, arg[1])
                && un.unifies(p2, arg[2]));
    }
}